﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;
using System.Data;
using VINETLIFE.AdminCP;
using System.Web.UI.HtmlControls;

namespace VINETLIFE.Customers
{
    public partial class ClientSystem : System.Web.UI.Page
    {
        cmsCustomerDO objCus = new cmsCustomerDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CustomerId"] != null)
            {
                objCus.Id = int.Parse(Session["CustomerId"].ToString());
                if (!IsPostBack)
                {
                    SEO();
                    InitForm();
                }
            }
            else
            {
                Functions.Alert("Bạn không có quyền truy cập vào khi chưa đăng nhập, vui lòng đăng nhập", "/dang-nhap/?ReturnUrl=he-thong-khach-hang");
            }
        }

        private void SEO()
        {
            Page.Title = "Hệ thống khách hàng | " + Ultility.WebTitle();

            sysConfigDO objConfig = new sysConfigDO();
            objConfig.ConfigID = 2;

            objConfig = new sysConfigBL().Select(objConfig);


            HtmlMeta metaKey = new HtmlMeta();
            metaKey.Name = "keywords";
            metaKey.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaKey);


            objConfig.ConfigID = 3;
            objConfig = new sysConfigBL().Select(objConfig);
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            metaDesc.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaDesc);
        }
        private void InitForm()
        {
            VINETLIFE.Data.LinqVinetlifeDataContext linq = new Data.LinqVinetlifeDataContext();
            if (txtFromDate.Text.Equals("") || txtToDate.Text.Equals(""))
            {
                var query = from p in linq.cmsCustomers
                            where p.IntroductionCustomerId == objCus.Id
                            select p;
                grvAccountReceivedMoney.DataSource = query;
            }
            else
            {
                var query = from p in linq.cmsCustomers
                            where p.IntroductionCustomerId == objCus.Id && (p.CreatedDate.Value >= Myfunction.ReturnValidateDateTime(txtFromDate.Text) && p.CreatedDate.Value <= Myfunction.ReturnValidateDateTime(txtToDate.Text))
                            select p;
                grvAccountReceivedMoney.DataSource = query;
            }
            grvAccountReceivedMoney.DataBind();
        }


        protected void btnHuy_Click(object sender, EventArgs e)
        {
            InitForm();
        }

        protected void grvAccountReceivedMoney_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            InitForm();
        }

        protected void grvAccountReceivedMoney_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
        }
    }
}
